import { ApiProperty,getSchemaPath,ApiExtraModel } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { ApiRes, PaginationDto } from '.';
export class AnnouncementId {
  @ApiProperty({ description: '公告id', required: true })
  @Rule(RuleType.number().required().error(new Error('公告id不能为空')))
  id: number
}
export class AnnouncementOther extends AnnouncementId{
  @ApiProperty({ description: '创建时间' })
  createdAt: string

  @ApiProperty({ description: '创建人姓名' })
  creatorName:string
}

export class AnnouncementCommon {
  @ApiProperty({ description: '公告标题', required: true })
  @Rule(RuleType.string().required().error(new Error('公告标题不能为空')))
  title: string

  @ApiProperty({ description: '公告内容', required: true })
  @Rule(RuleType.string().required().error(new Error('公告内容不能为空')))
  content: string
}

export class AnnouncementEdit extends AnnouncementCommon{
  @ApiProperty({ description: '公告id', required: true })
  @Rule(RuleType.number().required().error(new Error('公告id不能为空')))
  id: number
}

export class AnnouncementItem extends AnnouncementOther{
  @ApiProperty({ description: '公告标题', required: true })
  @Rule(RuleType.string().required().error(new Error('公告标题不能为空')))
  title: string

  @ApiProperty({ description: '公告内容', required: true })
  @Rule(RuleType.string().required().error(new Error('公告内容不能为空')))
  content: string
}

@ApiExtraModel(AnnouncementItem)
export class AnnouncementItemRes {
  @ApiProperty({
    type: 'array',
    items: {
      $ref: getSchemaPath(AnnouncementItem),
    }
  })
  list: AnnouncementItem[];
  @ApiProperty({ type: PaginationDto, description: '分页' })
  pagination: PaginationDto;
}

export class AnnouncementItemResDto extends ApiRes<AnnouncementItemRes>(
  AnnouncementItemRes
) {}
